function dataURLtoBlob(dataurl) {
  var arr = dataurl.split(',')
  var mime = arr[0].match(/:(.*?);/)[1]
  var bstr =atob(arr[1])
  var n = bstr.length
  var u8arr =new Uint8Array(n)
  while (n--) {
    u8arr[n] = bstr.charCodeAt(n)
  }
  return new Blob([u8arr], {type: mime })
}

function blobToFile(blob, fileName){
  blob.lastModifiedDate =new Date()
  blob.name = fileName
  return blob
}

export function dataURLtoFile(dataurl, filename){
  // eslint-disable-next-line no-unused-vars
  var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
    bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n)
  while(n--){
    u8arr[n] = bstr.charCodeAt(n)
  }
  var blob = dataURLtoBlob(dataurl)
  return blobToFile(blob, filename)
}